package com.software.loginregister.databasesHelper;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.software.loginregister.entity.room.WorksCache;

import java.util.List;

@Dao
public interface WorksCacheDao {
    @Query("SELECT * FROM works_cache ORDER BY timestamp DESC")
    List<WorksCache> getAllWorks();

    @Insert
    void insertAll(List<WorksCache> caches);

    @Query("DELETE FROM works_cache")
    void deleteAll();

    @Query("SELECT COUNT(*) FROM works_cache")
    int getCacheCount();

    @Query("DELETE FROM works_cache WHERE timestamp < :expiryTime")
    void deleteExpiredCache(long expiryTime);

    @Query("DELETE FROM works_cache WHERE id IN (SELECT id FROM works_cache ORDER BY timestamp ASC LIMIT :count)")
    void deleteOldestCache(int count);
}